/*
 * np_file.h
 *
 *  Created on: Dec 13, 2010
 *      Author: jeff_zheng
 *   Copyright: NetPerform Technology
 */

#ifndef NP_FILE_H_
#define NP_FILE_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef enum np_file_type_e
{
	NP_FILE_TYPE_DIR = 1,
	NP_FILE_TYPE_REG = 2,
	NP_FILE_TYPE_OTH = 3,
}np_file_type_t;


int np_file_path_remove(const np_cstr path);
int np_file_path_remove2(const np_cstr path1, const np_cstr path2);

int np_file_dir_create(const np_cstr path);
int np_file_path_get_type(const np_cstr path, np_file_type_t* ret_type);

int np_file_create_file(const np_cstr path, uint64_t size, np_bool fill_zero);
int np_file_create_file2(const np_cstr path1, const np_cstr path2, uint64_t size, np_bool fill_zero);
int np_file_open_file(const np_cstr path);

typedef struct np_file_map_s
{
	uint8_t* p_map_usr;
	uint64_t usr_length;
	void* _p_map;
	uint64_t _map_length;
}np_file_map_t;

int np_file_map_file(int fd, uint64_t length, uint64_t offset, np_file_map_t* p_map);
int np_file_unmap_file(np_file_map_t* p_map);

int np_file_read_all(const char* fname, char** pp_ret_data, uint32_t* p_size);
int np_file_write_all(const char* fname, const char* p_buf, uint32_t size);

typedef int (*np_file_dir_for_each_cbf)(const np_cstr path, const np_cstr fname, const np_cstr full_path, np_file_type_t ftype, void* p_arg);
int np_file_dir_for_each(const np_cstr path, np_file_dir_for_each_cbf p_cbf, void* p_arg);

#ifdef __cplusplus
}
#endif

#endif /* NP_FILE_H_ */
